﻿@model WebEditor.Models.Exits

<table>
    <tr>
        <td style="vertical-align: top">
            <table>
                <tr>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    @CompassDirection("nw", Model.Directions[0])
                                </td>
                                <td>
                                    @CompassDirection("n", Model.Directions[1])
                                </td>
                                <td>
                                    @CompassDirection("ne", Model.Directions[2])
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @CompassDirection("w", Model.Directions[3])
                                </td>
                                <td>
                                </td>
                                <td>
                                    @CompassDirection("e", Model.Directions[4])
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @CompassDirection("sw", Model.Directions[5])
                                </td>
                                <td>
                                    @CompassDirection("s", Model.Directions[6])
                                </td>
                                <td>
                                    @CompassDirection("se", Model.Directions[7])
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    @CompassDirection("up", Model.Directions[8])
                                </td>
                                <td>
                                    @CompassDirection("in", Model.Directions[10])
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @CompassDirection("down", Model.Directions[9])
                                </td>
                                <td>
                                    @CompassDirection("out", Model.Directions[11])
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
        <td style="vertical-align: top">
            <div id="@Model.Id-exit-data" style="display: none" class="compassDirectionEditor ui-corner-all">
                <b><span id="@Model.Id-exit-data-name"></span></b><br /><br />
                <div id="@Model.Id-exit-data-existing" style="display: none">
                    To: <span id="@Model.Id-exit-data-to"></span><br /><br />
                    <button type="button" class="compass-direction-edit" id="@Model.Id-exit-data-edit">Edit</button>
                </div>
                <div id="@Model.Id-exit-data-create" style="display: none">
                    <b>Create an exit:</b><br />
                    To: @Html.DropDownList(Model.Id + "-exit-data-create-to", Model.Objects.Select(o => new SelectListItem { Text = o, Value = o }))
                    <br /><br />
                    <button type="button" class="compass-direction-create" id="@Model.Id-exit-data-create-new" data-key="@Model.Id">Create exit</button>
                    <br /><br />
                    @Html.CheckBox(Model.Id + "-exit-data-create-inverse", Model.CreateInverse)
                    @Html.Label(Model.Id + "-exit-data-create-inverse", "Also create exit in the other direction")
                    @if (!Model.SimpleMode)
                    {
                        <hr />
                        <b>Or create a "look" direction:</b><br /><br />
                        <text>Allows players to look in this direction, but not move this way.</text><br /><br />
                        <button type="button" class="compass-direction-create-look" id="@Model.Id-exit-data-create-look" data-key="@Model.Id">Create "look" direction</button>
                    }
                </div>
            </div>
        </td>
    </tr>
</table>

<div class="ui-widget-header ui-corner-all toolbar" style="margin-top: 20px">
    <button type="button" class="exitslist-add" id="@Model.Id-exit-add" data-key="@Model.Id">Add</button>
    <button type="button" class="exitslist-edit" id="@Model.Id-exit-edit" data-key="@Model.Id">Edit</button>
    <button type="button" class="exitslist-delete" id="@Model.Id-exit-delete" data-key="@Model.Id">Delete</button>
    <button type="button" class="exitslist-moveup" id="@Model.Id-exit-moveup" data-key="@Model.Id">Move up</button>
    <button type="button" class="exitslist-movedown" id="@Model.Id-exit-movedown" data-key="@Model.Id">Move down</button>
</div>

<div>
    <select id="exitslist-@Model.Id" data-key="@Model.Id" size="8" style="width: 100%" class="exitslist">
        @foreach (var item in Model.AllExits.Values)
        {
            <option value="@item.Name" data-previous="@item.Previous" data-next="@item.Next">@item.To</option>
        }
    </select>
</div>

@helper CompassDirection(string direction, WebEditor.Models.Exits.CompassDirection data)
{
    string compassId = Model.Id + "-compass" + direction.ToUpper();
    <div class="compassDirection ui-corner-all" data-option="@compassId" data-key="@Model.Id">
        @Html.RadioButton(Model.Id + "-compass", direction, new
        {
            id = compassId,
            @class = "compass-direction",
            data_key = Model.Id,
            data_id = data.ElementId,
            data_name = data.Name,
            data_to = data.To,
            data_inverse = data.InverseName,
            data_type = data.DirectionType,
            data_inversetype = data.InverseDirectionType,
            data_lookonly = data.LookOnly ? "1" : "0"
        })
        @Html.Label(compassId, data.Name)<br /><br />
        <div class="compassDirectionInfo">
            @if (data.LookOnly)
            {
                <text>(look)</text>
            }
            else
            {
                <a class="compass-direction-link">@data.To</a>
            }
        </div>
    </div>
}